**********************************
*	Title: labor04.do
*	Date: 30 May 2006
*	Author: Zoe McLaren
*	Description: Creates new variables for analysis.

**********************************

use "$data/hhindiv04.dta", clear  

drop if group==.  /*drop unmatched hholds (that have some hhold data)*/

*hivstat
replace hivstat=. if hivstat<0  /*youngchild has negative values - should be missing*/
gen positive=1 if hivstat==1
replace positive=0 if hivstat==2
*tested already exists

drop agefive
ren agefveb agefive
replace agefive=. if agefive<0

cap ren race race_old
gen race=.
cap lab def race 1 "african" 2 "white" 3 "coloured" 4 "indian"  /*race label already defined*/
lab val race race
replace race=1 if african==1
replace race=2 if white==1
replace race=3 if coloured==1
replace race=4 if indian==1

********** HHOLD HIV VARIABLES **********
cap drop temp
gen temp=1 if hiv_diag==1 
egen anyhiv_diag=sum(temp), by(hhid)
lab var anyhiv_diag "anyone in hh diagnosed with hiv/aids, q16_1"
replace temp=.

replace temp=1 if hivstat==1
egen anyhiv_tested=sum(temp), by(hhid)
lab var anyhiv_tested "hh member tested for hiv (hivstat)"
replace temp=.

replace temp=1 if hiv_death==1 & group==1  
egen anyhiv_death=sum(temp), by(hhid)
lab var anyhiv_death "anyone died from aids in last 12 months (q16_2)"
replace temp=.

replace temp=1 if hiv_sick==1 & group==1
egen anyhiv_sick=sum(temp), by(hhid)
lab var anyhiv_sick "hh member currently bedridden with aids-related illness (q16_3)"
replace temp=.

replace temp=1 if hiv_time==1 & group==1 
egen anyhiv_time=sum(temp), by(hhid)
lab var anyhiv_time "time out of normal activities to care of person with HIV (q16_4)"
replace temp=.

gen anyhiv_timedays=hiv_timedays if group==1
lab var anyhiv_timedays "# days out to care for sick hh member in last 12 months (q16_5)"
replace anyhiv_timedays=888888 if hiv_timedaysdk==1 & group==1
lab def q16_5 1 "1" 888888 "don't know", modify
lab val anyhiv_timedays q16_5

gen anyhiv_spend=hiv_spend if group==1
lab var anyhiv_spend "amount usually spent per month to care for sick hh member (q16_6)"
replace anyhiv_spend=888888 if hiv_spenddk==1 & group==1

replace temp=1 if hiv_borrow==1 & group==1 
egen anyhiv_borrow=sum(temp), by(hhid)
lab var anyhiv_borrow "borrowed money to care for sick in last 12 months (q16_7)"
replace temp=.

gen anyhiv_borrowamt=hiv_borrowamt if group==1
lab var anyhiv_borrowamt "amount borrowed in last 12 months to care for sick (q16_8)"
replace anyhiv_borrowamt=888888 if hiv_borrowamtdk==1 & group==1
lab val anyhiv_borrowamt q16_5  /*label same as q16_5*/

replace temp=1 if hiv_bury==1 & group==1 
egen anyhiv_bury=sum(temp), by(hhid)
lab var anyhiv_bury "borrowed money to bury someone who died of AIDS in last year (q16_11)"
replace temp=.

replace temp=1 if hiv_sell==1 & group==1
egen anyhiv_sell=sum(temp), by(hhid)  /*only 20 sold, not worth recoding what was sold (q16_13)*/
lab var anyhiv_sell "sold property to care for someone with HIV in last year (q16_12)"
replace temp=.

replace temp=1 if grant==1 & group==1
egen anygrant=sum(temp), by(hhid) 
lab var anygrant "receive any form of grant or pension (q1_17)"
replace anygrant=1 if anygrant>=1 & anygrant<.
replace temp=.

foreach sub in diag tested death sick time borrow bury sell {
	replace anyhiv_`sub'=1 if anyhiv_`sub'>=1 & anyhiv_`sub'<.
}

********** LABOR MARKET VARIABLES **********

lab def empstat 1 "employed-ft" 2 "employed-pt" 3 "unemployed-searching" 4 "unemployed-not searching" /*
		*/ 5 "student/pupil" 6 "out of labour force"

gen empstat=1 if employment==9 | employment==12 
replace empstat=2 if employment==10 | employment==11 | employment==5 
replace empstat=3 if employment==2 | employment==3 
replace empstat=4 if employment==4 
replace empstat=5 if employment==8 
replace empstat=6 if employment==1 | employment==6 | employment==7 
*no specific question about retired: but OAP good proxy

lab val empstat empstat 
lab var empstat "labour market status" 

tab empstat, gen(empstat) 
lab var empstat1 "ft work" 
lab var empstat2 "pt work" 
lab var empstat3 "search ue" 
lab var empstat4 "discouraged" 
lab var empstat5 "student" 
lab var empstat6 "nlf" 

********** HOUSEHOLD VARIABLES **********
*q1-q11 (q12 only 5 hh said yes)

*q1: source of drinking water
ren q1 watersource
qui tab watersource, gen(watersource)
gen electricity=(q2==1)
lab var electricity "does hh have access to electricity, vpq2"
quietly tab q3 if q3<5, gen(cooking)
** note: some of these vars might be coded 1/2 instead of 0/1
ren q4 toilet
qui tab toilet, gen(toilet)
gen fridge=(q5a==1)
lab var fridge "vp q5a"
gen radio=(q5b==1)
lab var radio "vp q5b"
gen tv=(q5c==1)
lab var tv "vp q5c"
gen telephone=(q5d==1)
lab var telephone "vp q5d"
gen hhdisability=(q6==1)
lab var hhdisability "any hh residents have disability, vp q6"
gen homecare=(q7==1)
lab var homecare "hh resident cared for my home-based care, vp q7"

gen govtprog1=(q8e==1)
lab var govtprog1 "hh member in National school nutrition programme, vp q8e"
gen govtprog2=(q8f==1)
lab var govtprog2 "hh member in Working for water programme, vp q8f"
gen govtprog3=(q8g==1)
lab var govtprog3 "hh member in Working for the coast programme, vp q8g"
gen govtprog4=(q8h==1)
lab var govtprog4 "hh member in Public works projects, vp q8h"

gen burialsociety=(q9==1)
lab var burialsociety "belongs to burial society, vp q9"
gen migrants=(q10==1)
lab var migrants "hh has at least one migrant worker"
gen caretaker=(q11==1)
lab var caretaker "child-headed hh has a caretaker"

save "$data/hhindiv04_labor.dta", replace

exit  /* EXIT */
